package 剑指offer;

import javax.sql.rowset.spi.SyncResolver;
import java.util.*;

public class 字符串的排列 {
    public static void main(String[] args) {
        String str ="abc";
        combine(str.toCharArray(),0,str.length());

    }

    public static void combine(char[] str,int start,int end){
        if (start == end){
            System.out.println(str);
        }else{
            for(int j=start;j<end;j++){
                if (str[start] == str[j] && start!=j) continue;  //不同位置的相同字符不交换，避免重复
                swap(str,start,j);
                combine(str,start+1,end);//递归
                swap(str,start,j);  //还原字符串，为下一for循环准备

            }
        }

    }

    public static void swap(char[] str,int i,int j){
        char tmp = str[i];
        str[i] = str[j];
        str[j] = tmp;
    }



}
